$(document).ready(function () {
    //加载长沙市下面的区县
    $.ajax({
        method: 'POST',
        url: '/csfy/intf.do',
        data: {
            method: 'getAddrs',
            parentId: 4301,
        },
        success: function (res) {
            if (res && res.code == 200) {
                var rows = res.rows || []
                var options = "<option value=''>请选择区县</option>"
                rows.map((item) => {
                    options += "<option value='" + item.name + "'>" + item.name + "</option>"
                })
                $(".addressCounty").html(options);
            }
        }
    })
})


//选择区县变化监听
function onAddressCountyChange(value,productCode) {
    var data = {
        method: 'getCustomers'
    }
    var addressCounty = value;
    if(addressCounty == '宁乡市'){
        addressCounty = '宁乡县';
    }
    if (addressCounty) {
        data.addressCounty = addressCounty;
    } else {
        data.addressCity = '长沙市';
    }
    data.productCode = productCode;
    $.ajax({
        method: 'POST',
        url: '/csfy/intf.do',
        data: data,
        success: function (res) {
            var rows = res.rows
            var cusStr = '';
            if (rows) {
                for (var key in rows) {
                    var obj = rows[key];
                    var str = '<li id="customer-' + key + '" data-input="' + obj['customerCode'] + '" data-value="' + obj['customerName'] + '" class="sel-info" onclick="selCustomer(this);">' + obj['customerName'] + '</li><div class="input-line"></div>';
                    cusStr += str;
                }
                $('#customerBox').html(cusStr);
            } else {
                var str = '<li style="text-align:center;color: #00afee;" id="customer-' + 0 + '" data-input="' + '' + '" data-value="' + '' + '" class="sel-info" onclick="selCustomer(this);">' + '没有数据' + '</li><div class="input-line"></div>';
                $('#customerBox').html(str);
            }
        }
    })
}